// test_css3_values.js
// by SWC
// entry_function: start_css3_units_test()

var prefixes="-webkit- -moz- -o- -ms- ".split(" "),
			domPrefixes="webit moz o ms".split(" "),
			modElem=document.createElement("mod"),
			mStyle=modElem.style,
			docElement = document.documentElement;
	
	/**
     * testProps is a generic CSS / DOM property test; if a browser supports
     *   a certain property, it won't return undefined for it.
     *   A supported CSS property returns empty string when its not yet set.
     */
function testProps( props, prefixed ) {
	for ( var i in props ) {
		if ( mStyle[ props[i] ] !== undefined ) {
			return prefixed == 'pfx' ? props[i] : true;
		}
	}
	return false;
}

/**
 * testPropsAll tests a list of DOM properties we want to check against.
 *   We specify literally ALL possible (known and/or likely) properties on
 *   the element including the non-vendor prefixed one, for forward-
 *   compatibility.
 */
function testPropsAll( prop, prefixed ) {
	var ucProp  = prop.charAt(0).toUpperCase() + prop.substr(1),
		props   = (prop + ' ' + domPrefixes.join(ucProp + ' ') + ucProp).split(' ');
	return testProps(props, prefixed);
}
//is returns a boolean for if typeof obj is exactly type.
function is( obj, type ) {
	return typeof obj === type;
}   
// contains returns a boolean for if substr is found within str.
function contains( str, substr ) {
	return !!~('' + str).indexOf(substr);
}

function Supported_values(para1,para2,name){
	setCss(para1+para2+';');
	if(contains(mStyle.cssText, name)||(contains(mStyle.cssText, para2)&&para2!==''))
		return true;
	else
		return false;
}

function Supported_values_other(para,name){
	setCss(para)
	if(contains(mStyle.cssText, name)||contains(mStyle.cssText, para))
		return true;
	return false;
}

function result_tests(result){
	//TODO replace with sandbox

	result["units_length"] = {
		layerName:	"Length",
		type:"aggrg",
		nlist: {
			"rem": Supported_values('font-size:12','rem','rem'),
			"vw": Supported_values('font-size:8','vw','vw'),
			"vm": Supported_values('font-size:8','vm','vm')
		}
	};
	
	result["units_angle"] = {
		layerName:	"Angle",
		type:"aggrg",
		nlist: {
			"deg": Supported_values('-moz-transform:rotate(2deg);-webkit-transform:rotate(2deg);-o-transform:rotate(2deg);-ms-transform:rotate(2deg);transform:rotate(2deg);','','deg'),
			"grad":  Supported_values('-moz-transform:rotate(2grad);-webkit-transform:rotate(2grad);-o-transform:rotate(2grad);-ms-transform:rotate(2grad);transform:rotate(2grad);','','grad'),
			"rad":  Supported_values('-moz-transform:rotate(2rad);-webkit-transform:rotate(2rad);-o-transform:rotate(2rad);-ms-transform:rotate(2rad);transform:rotate(2rad);','','rad'),
			"turn":Supported_values('-moz-transform:rotate(2rad);-webkit-transform:rotate(2rad);-o-transform:rotate(2rad);-ms-transform:rotate(2rad);transform:rotate(2rad);','','rad')
		}
	};
	
	result["units_time"] = {
		layerName:	"Time",
		type:"aggrg",
		nlist: {
			"s": Supported_values('-moz-transition-duration:.5s;-webkit-transition-duration:.5s;-o-transition-duration:.5s;-ms-transition-duration:.5s;transition-duration:.5s;','','s'),
			"ms": Supported_values('-moz-transition-duration:50ms;-webkit-transition-duration:50ms;-o-transition-duration:50ms;-ms-transition-duration:50ms;transition-duration:50ms;','','ms')
		}
	};
	
	result["units_frequency"] = {
		layerName:	"Frequency",
		type:"aggrg",
		nlist: {
			"fr": Supported_values('border-parts:10px 1fr 10px;','','fr'),
			"gr": Supported_values('float-offset:2gr;','','gr')
		}
	};
}


function start_css3_units_test(container){
	var E = {
		layerName: "CSS3 Values",
		type: "aggrg",
		nlist: {}
	};
	result_tests(E.nlist);
	return E;
}
	